﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Framework.Event;
using Microsoft.Practices.Unity;
using Framework.Config;

namespace Framework.Bus
{
    public class SyncBusImpl<TMessage> : ISyncBus<TMessage>
        where TMessage : IMessage
    {
        IMessageDispatcher _Dispatcher;

        public SyncBusImpl(IMessageDispatcher dispatcher)
        {
            _Dispatcher = dispatcher;
        }

        #region IAsyncBus<IDomainEvent> Members

        public void Commit()
        {
            throw new NotImplementedException();
        }

        #endregion

        #region IBus<IDomainEvent> Members

        public void Send(TMessage message)
        {
            _Dispatcher.DispatchMessage(message);
        }

        public void Send(IEnumerable<TMessage> messages)
        {
            foreach (var message in messages)
            {
                Send(message);
            }
        }

        #endregion

        #region IDisposable Members

        public void Dispose()
        {
            
        }

        #endregion

        #region IBus<TMessage> Members


        public void Publish(TMessage message)
        {
            _Dispatcher.DispatchMessage(message);
        }

        public void Publish(IEnumerable<TMessage> messages)
        {
            foreach (var message in messages)
            {
                Publish(message);
            }
        }

        #endregion
    }
}
